package com.heima.admin.listener;

import com.alibaba.fastjson.JSON;
import com.heima.admin.service.WemediaNewsAutoScanService;
import com.heima.model.common.constants.NewsAutoScanConstants;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

import java.util.Map;
import java.util.Optional;

@Component
@Slf4j
public class WemediaNewsAutoListener {

    @Autowired
    WemediaNewsAutoScanService autoScanService;

    @KafkaListener(topics = NewsAutoScanConstants.WM_NEWS_AUTO_SCAN_TOPIC)
    public void recevieMessage(String message){
        log.info("=====================================监听到文章信息开始审核文章内容:{}",message);
        if (Optional.ofNullable(message).isPresent()){
            Map<String, Integer> map = JSON.parseObject(message, Map.class);
            autoScanService.autoScanByMediaNewsId(map.get("WmNewsId"));
            log.info("**********************************文章审核通过******************************");
        }
    }
}
